Telegram Group & Telegram Channel
📚 Загадочная библиотека setjmp.h — неочевидный инструмент для управления потоком выполнения


Библиотека setjmp.h предоставляет два необычных макроса:

setjmp — сохраняет текущее состояние программы (регистры, стек) в буфер jmp_buf

longjmp — «откатывает» выполнение к сохранённому состоянию, как прыжок во времени



#include <stdio.h>
#include <setjmp.h>

jmp_buf jump_buffer;

void risky_function() {
printf("Готовимся к прыжку...\n");
longjmp(jump_buffer, 42); // Прыжок обратно в setjmp!
}

int main() {
int ret = setjmp(jump_buffer);
if (ret == 0) {
printf("Первая инициализация...\n");
risky_function();
} else {
printf("Вернулись с кодом: %d\n", ret); // Выведет 42!
}
return 0;
}


⚠️ Осторожно!

• Не заменяет исключения — нет вызова деструкторов (как в C++)
• Опасность утечек — если между setjmp и longjmp выделялась память, она не освободится
• Портит стек — может сломать логику функций

🛠 Где может пригодиться?

• Обработка критических ошибок (а-ля «аварийный выход»)
• Код для встраиваемых систем, где нужно быстро восстановить состояние
• Нестандартные хаки (но лучше так не делать 😈)

Библиотека C/C++ разработчика



tg-me.com/cppproglib/5619
Create:
Last Update:

📚 Загадочная библиотека setjmp.h — неочевидный инструмент для управления потоком выполнения


Библиотека setjmp.h предоставляет два необычных макроса:

setjmp — сохраняет текущее состояние программы (регистры, стек) в буфер jmp_buf

longjmp — «откатывает» выполнение к сохранённому состоянию, как прыжок во времени



#include <stdio.h>
#include <setjmp.h>

jmp_buf jump_buffer;

void risky_function() {
printf("Готовимся к прыжку...\n");
longjmp(jump_buffer, 42); // Прыжок обратно в setjmp!
}

int main() {
int ret = setjmp(jump_buffer);
if (ret == 0) {
printf("Первая инициализация...\n");
risky_function();
} else {
printf("Вернулись с кодом: %d\n", ret); // Выведет 42!
}
return 0;
}


⚠️ Осторожно!

• Не заменяет исключения — нет вызова деструкторов (как в C++)
• Опасность утечек — если между setjmp и longjmp выделялась память, она не освободится
• Портит стек — может сломать логику функций

🛠 Где может пригодиться?

• Обработка критических ошибок (а-ля «аварийный выход»)
• Код для встраиваемых систем, где нужно быстро восстановить состояние
• Нестандартные хаки (но лучше так не делать 😈)

Библиотека C/C++ разработчика

BY Библиотека C/C++ разработчика | cpp, boost, qt




Share with your friend now:
tg-me.com/cppproglib/5619

View MORE
Open in Telegram


Библиотека C C разработчика | cpp boost qt Telegram | DID YOU KNOW?

Date: |

That strategy is the acquisition of a value-priced company by a growth company. Using the growth company's higher-priced stock for the acquisition can produce outsized revenue and earnings growth. Even better is the use of cash, particularly in a growth period when financial aggressiveness is accepted and even positively viewed.he key public rationale behind this strategy is synergy - the 1+1=3 view. In many cases, synergy does occur and is valuable. However, in other cases, particularly as the strategy gains popularity, it doesn't. Joining two different organizations, workforces and cultures is a challenge. Simply putting two separate organizations together necessarily creates disruptions and conflicts that can undermine both operations.

How to Use Bitcoin?

n the U.S. people generally use Bitcoin as an alternative investment, helping diversify a portfolio apart from stocks and bonds. You can also use Bitcoin to make purchases, but the number of vendors that accept the cryptocurrency is still limited. Big companies that accept Bitcoin include Overstock, AT&T and Twitch. You may also find that some small local retailers or certain websites take Bitcoin, but you’ll have to do some digging. That said, PayPal has announced that it will enable cryptocurrency as a funding source for purchases this year, financing purchases by automatically converting crypto holdings to fiat currency for users. “They have 346 million users and they’re connected to 26 million merchants,” says Spencer Montgomery, founder of Uinta Crypto Consulting. “It’s huge.”

Библиотека C C разработчика | cpp boost qt from es


Telegram Библиотека C/C++ разработчика | cpp, boost, qt
FROM USA